"use strict";
// 抽象工厂（TypeScript 版本）
// - 提供两组产品示例：主题组件（Button / Input）和请求（GET / POST）
// - 使用抽象类/接口保证类型安全
Object.defineProperty(exports, "__esModule", { value: true });
exports.ProdRequestFactory = exports.DevRequestFactory = exports.ProdPostRequest = exports.ProdGetRequest = exports.DevPostRequest = exports.DevGetRequest = exports.PostRequest = exports.GetRequest = exports.RequestFactory = exports.LightThemeFactory = exports.DarkThemeFactory = exports.LightInput = exports.LightButton = exports.DarkInput = exports.DarkButton = exports.Input = exports.Button = exports.ThemeFactory = void 0;
exports.demoTheme = demoTheme;
exports.demoRequest = demoRequest;
// ==================== 主题工厂 ====================
class ThemeFactory {
}
exports.ThemeFactory = ThemeFactory;
class Button {
}
exports.Button = Button;
class Input {
}
exports.Input = Input;
class DarkButton extends Button {
    render() {
        console.log('渲染黑色按钮，文字白色');
    }
}
exports.DarkButton = DarkButton;
class DarkInput extends Input {
    render() {
        console.log('渲染黑色输入框，文字白色');
    }
}
exports.DarkInput = DarkInput;
class LightButton extends Button {
    render() {
        console.log('渲染白色按钮，文字黑色');
    }
}
exports.LightButton = LightButton;
class LightInput extends Input {
    render() {
        console.log('渲染白色输入框，文字黑色');
    }
}
exports.LightInput = LightInput;
class DarkThemeFactory extends ThemeFactory {
    createButton() {
        return new DarkButton();
    }
    createInput() {
        return new DarkInput();
    }
}
exports.DarkThemeFactory = DarkThemeFactory;
class LightThemeFactory extends ThemeFactory {
    createButton() {
        return new LightButton();
    }
    createInput() {
        return new LightInput();
    }
}
exports.LightThemeFactory = LightThemeFactory;
// ==================== 请求工厂 ====================
// 抽象工厂：生成环境相关的请求对象
class RequestFactory {
}
exports.RequestFactory = RequestFactory;
class GetRequest {
    constructor(baseUrl, url) {
        this.fullUrl = `${baseUrl}${url}`;
    }
}
exports.GetRequest = GetRequest;
class PostRequest {
    constructor(baseUrl, url, data) {
        this.fullUrl = `${baseUrl}${url}`;
        this.data = data;
    }
}
exports.PostRequest = PostRequest;
class DevGetRequest extends GetRequest {
    send() {
        console.log(`Dev环境GET请求：${this.fullUrl}`);
    }
}
exports.DevGetRequest = DevGetRequest;
class DevPostRequest extends PostRequest {
    send() {
        console.log(`Dev环境POST请求：${this.fullUrl}，数据：${JSON.stringify(this.data)}`);
    }
}
exports.DevPostRequest = DevPostRequest;
class ProdGetRequest extends GetRequest {
    send() {
        console.log(`Prod环境GET请求：${this.fullUrl}`);
    }
}
exports.ProdGetRequest = ProdGetRequest;
class ProdPostRequest extends PostRequest {
    send() {
        console.log(`Prod环境POST请求：${this.fullUrl}，数据：${JSON.stringify(this.data)}`);
    }
}
exports.ProdPostRequest = ProdPostRequest;
class DevRequestFactory extends RequestFactory {
    constructor() {
        super(...arguments);
        this.baseUrl = 'http://dev.api.com';
    }
    createGet(url) {
        return new DevGetRequest(this.baseUrl, url);
    }
    createPost(url, data) {
        return new DevPostRequest(this.baseUrl, url, data);
    }
}
exports.DevRequestFactory = DevRequestFactory;
class ProdRequestFactory extends RequestFactory {
    constructor() {
        super(...arguments);
        this.baseUrl = 'http://prod.api.com';
    }
    createGet(url) {
        return new ProdGetRequest(this.baseUrl, url);
    }
    createPost(url, data) {
        return new ProdPostRequest(this.baseUrl, url, data);
    }
}
exports.ProdRequestFactory = ProdRequestFactory;
// ==================== 演示 / 使用 ====================
function demoTheme() {
    const darkTheme = new DarkThemeFactory();
    darkTheme.createButton().render();
    darkTheme.createInput().render();
    const lightTheme = new LightThemeFactory();
    lightTheme.createButton().render();
    lightTheme.createInput().render();
}
function demoRequest() {
    const devFactory = new DevRequestFactory();
    devFactory.createGet('/user').send();
    devFactory.createPost('/user', { name: '张三' }).send();
    const prodFactory = new ProdRequestFactory();
    prodFactory.createGet('/health').send();
    prodFactory.createPost('/log', { event: 'start' }).send();
}
// 运行 demo（直接执行此文件时）
console.log('--- Theme Demo ---');
demoTheme();
console.log('\n--- Request Demo ---');
demoRequest();
